package com.yw.wanandroid.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.yw.wanandroid.R
import com.yw.wanandroid.databinding.RvItemArticleBinding
import com.yw.wanandroid.model.HomeTopArticleModel

class HomeAdapter(var list: ArrayList<HomeTopArticleModel>) :
    RecyclerView.Adapter<HomeAdapter.HomeViewItemHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewItemHolder {
        return HomeViewItemHolder(
            DataBindingUtil.inflate(
                LayoutInflater.from(parent.context),
                R.layout.rv_item_article,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: HomeViewItemHolder, position: Int) {
        holder.binding.bean = list[position]

    }

    override fun getItemCount(): Int {
        return list.size
    }

    class HomeViewItemHolder(var binding: RvItemArticleBinding) :
        RecyclerView.ViewHolder(binding.root)

}
